package com.spark.lola.logistics.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spark.lola.logistics.entity.OrderInfo;
import com.spark.lola.logistics.vo.*;
import com.spark.lola.support.mybatis.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author: Zhi-peng wang
 * @date: 2020/04/26 16:08
 * 货运单mapper
 **/
@Mapper
public interface LogisticsOrderInfoMapper extends BaseMapper<OrderInfo> {

    /**
     * @description: 分页查询货运单信息
     * @author: wzp
     * @date: 2020/4/27
     */
    IPage<OrderInfoVo> findPage(Page<OrderInfoVo> page, @Param(Constants.WRAPPER) Wrapper<OrderInfoVo> wrapper);

    IPage<OrderCompleteVo> findCompletePage(Page<OrderCompleteVo> page, @Param(Constants.WRAPPER) Wrapper<OrderCompleteVo> wrapper);

    @Select("select version from logistics_order_info where id=#{id}")
    int findVersionById(long id);

    @Select("select car_id from logistics_order_info where id=#{id}")
    long findCarIdById(long id);

    @Select("select semitrailer_no from logistics_order_info where id=#{id}")
    String findSemitrailerNo(long id);

    List<StatisticsOrderInfoVo> findStatistics(int status, Date startTime, Date endTime, Long driverId, Long carId);

    @Select("select count(*) from logistics_order_info where creator_id=528 and status>=1")
    int countOtherCar();

    @Select("select count(*) from logistics_order_info where status=#{status}")
    int countByStatus(int status);

    List<BigDecimal> findTransportTotal(int status, String startTime, String endTime, long productId);

    @Select("select start_area_ids endAreaIds,start_area endArea,start_address endAddress," +
            "end_area_ids startAreaIds,end_area startArea,end_address startAddress " +
            "from logistics_order_info where creator_id=#{createId} order by create_time desc limit 0,1")
    MatchToOrderLocationVo queryMatchTo(long createId);

    int countStatistic(int type, int status, Date startTime, Date endTime);

    List<OrderStatisticVo> queryByDate(int status, Date startTime, Date endTime);

}
